import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter)

import page1  from '../components/page1.vue';
import page2  from '../components/page2.vue';
import Home from './../components/home/Home';
import zhaoping from './../components/zhaoping/zhaoping';
import rencai from './../components/rencai/rencai';
import Login from "../components/Login";
import NewDetail from './../components/rencai/Detail'
import StudyVideo from "../components/studyvideo/StudyVideo";
import PlayVideo from "../components/studyvideo/PlayVideo";
import PersonInfoPage from "../components/personinfo/PersonInfoPage";
import ModifyPassword from "../components/personinfo/ModifyPassword";
import BindAccount from "../components/personinfo/BindAccount";
import PersonalReg from "../components/register/PersonalReg";
import EnterpriseReg from "../components/register/EnterpriseReg";
import EnterprisePage from "../components/enterprise/EnterprisePage";
import EnterpriseBasePage from "../components/enterprise/EnterpriseBasePage"
import RecruitmentPage from "../components/enterprise/RecruitmentPage"
import ZhaoPingDetail from "../components/zhaoping/ZhaoPingDetail"
import PubJobInfo from "../components/enterprise/PubJobInfo";
import ModifyJobInfo from "../components/enterprise/ModifyJobInfo";

import wechat_image from "../components/wechat/image";
import wechat_video from "../components/wechat/video";

const routes=[
    {path:"/home",component:Home},
    {path:'/page1',component:page1},
    {path:'/NewDetail/*',component:NewDetail},
    {path:"/page2",component:page2},
    {path:"/zhaoping",component:zhaoping},
    {path:"/ZhaoPingDetail",component:ZhaoPingDetail},
    {path:"/rencai",component:rencai},
    {path:"/login",component:Login},
    {path:"/StudyVideo",component:StudyVideo},
    {path:"/PlayVideo",component:PlayVideo},
//注册
    {path:"/PersonalReg",component:PersonalReg},
    {path:"/EnterpriseReg",component:EnterpriseReg},
//企业用户
    {path:"/EnterprisePage",component:EnterprisePage},
    {path:"/EnterpriseBasePage",component:EnterpriseBasePage},
    {path:"/RecruitmentPage",component:RecruitmentPage},
    {path:"/PubJobInfo",component:PubJobInfo},
    {path:"/ModifyJobInfo/*",component:ModifyJobInfo},
//个人用户
    {path:"/PersonInfoPage",component:PersonInfoPage},
    {path:"/ModifyPassword",component:ModifyPassword},
    {path:"/BindAccount",component:BindAccount},

    {path:"/wechat/image",component:wechat_image},
    {path:"/wechat/video",component:wechat_video},

    //可以配置重定向
    {path:'',redirect:"home"},
    //或者重新写个路径为空的路由
    {path:"",component:Home}
]

const router=new VueRouter({
    routes
});


let AUTH_URL = ["/PersonInfoPage","/ModifyPassword","/BindAccount"];

router.beforeEach(async(to, from, next) => {
    if (to.fullPath === from.fullPath ) { //防止页面死循环
        next()
    } else if(AUTH_URL.includes(to.fullPath)) {
        if (!sessionStorage.getItem("token")) {
            next({ path: "login" })
        } else {
            next()
        }
    }else{
        next()
    }
});

export default router